/*
 * @Author: 姜跃龙
 * @Date: 2021-09-07 09:23:58
 * @LastEditors: 姜跃龙
 * @LastEditTime: 2021-09-07 09:38:19
 * @Description: file content
 */
export const resourceCode = process.env.VUE_APP_RESOURCE_CODE
export const moduleCode = process.env.VUE_APP_MODULE_CODE
let $http

export const createRequest = (vm) => {
    $http = vm.$http
}

export const request = async (options) => {
    if (!$http) {
        console.error('请求实例未创建！')
        return
    }
    // 相应拦截
    const onResponse = (res) => {
        console.log('onResponse', onResponse)
        return res
    }

    // 请求拦截
    const onRequest = (options) => {
        const copyOptions = JSON.parse(JSON.stringify(options))
        // copyOptions.url = 'portal-source/' + resourceCode + moduleCode + copyOptions.url
        return copyOptions
    }

    // 请求前
    const opt = onRequest(options)
    // 发请求
    const res = await $http(opt)
    // 请求后
    return onResponse(res)
}
